
function getQueryString() {
      var result = location.search.match(new RegExp("[\?\&][^\?\&]+=[^\?\&]+", "g"));
      for (var i = 0; i < result.length; i++) {
          result[i] = result[i].substring(1);
        }
        return result;
    }
//根据QueryString参数名称获取值
function getQueryStringByName(name) {
    var result = location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
    if (result == null || result.length < 1) {
        return "";
    }
    return result[1];
}
//根据QueryString参数索引获取值
function getQueryStringByIndex(index) {
    if (index == null) {
        return "";
    }
    var queryStringList = getQueryString();
    if (index >= queryStringList.length) {
        return "";
    }
    var result = queryStringList[index];
    var startIndex = result.indexOf("=") + 1;
    result = result.substring(startIndex);
    return result;
}

 // 获取gid aid 
 function soleAll(){
 var sole = $(".sole").html();
 console.log(sole)
    if(sole==1){
        $(".sole").css({"color":"#ffd200"});
    }else if(sole==2){
        $(".sole").css({"color":"#d3d3d3"});
    }else if(sole==3){
        $(".sole").css({"color":"#d9a86b"});
    }else{
         $(".sole").css({"font":"20px","color":"#4f4f4f"});
    }

}

var browser = {
    versions: function() {
    var u = navigator.userAgent, app = navigator.appVersion;
    return {//移动终端浏览器版本信息 
    trident: u.indexOf('Trident') > -1, //IE内核
    presto: u.indexOf('Presto') > -1, //opera内核
    webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
    gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
    mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
    ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
    android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
    iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者QQHD浏览器
    iPad: u.indexOf('iPad') > -1, //是否iPad
    webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
    };
    }(),
    language: (navigator.browserLanguage || navigator.language).toLowerCase()
    }
    
// 官方排行当前用户样式

function setCookie(c_name,value,expiredays,path)
    {
    var exdate=86400*expiredays
    path = "/";
    
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate) + ((path==null) ? "" : ";path="+path)
    }
       
  function getCookie(name)
    {
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
    if(arr=document.cookie.match(reg))
    return unescape(arr[2]);
    else
    return null;
    }         
      function app() {
        
        var isAppInstalled = "{$isAppInstalled}";
        var isAndroid = false;
        var iPhone = false;
        var userAgent = navigator.userAgent;
        var downloadUrl = "http://mobile.hupu.com/download/joggers?r=share";
        var uid = "{$userInfo['uid']}";
        if (userAgent.match("Android")){
            isAndroid = true;
        }else if (userAgent.match("iPhone")){
            iPhone = true;
            downloadUrl = "http://itunes.apple.com/cn/app/hu-pu-pao-bu/id869299193?mt=8";
        }
        var word = '下载虎扑跑步客户端';
        var url = downloadUrl;
        if(isAppInstalled == 1 || isAppInstalled == 3)
        {
             word = "{$isShare}" == '1'?'查看Ta的主页':'打开并添加好友';
             url = "{$isShare}" == '1'?'joggers://profile/'+uid:'joggers://invite/'+uid
        }
        else if(isAppInstalled == 0 || isAppInstalled == 2)
        {          
            word = '下载虎扑跑步客户端';
            url = downloadUrl;
        }
        $("#openBtn").text(word);
        $("#openBtn").attr("href",url);

        if(isAppInstalled == 0 || isAppInstalled == 1)
        {
            pointImg = 'http://irun.hupu.com/static/backend/wpoint_';
            pointImg += iPhone ? '2' : '1';
            pointImg += '.png?1';
            $("#point").attr("src", pointImg);
        }
        $("#openBtn").click(function(e){
            if(isAppInstalled == 0 || isAppInstalled == 1) //在微信中打开
            {
                // 阻止超链接跳转
                e.preventDefault();
                height = $(document).height();
                $("#shadow").attr("height",height);
                $("div#shadowDiv").addClass("on");
            }
            else if(isAppInstalled = -1)
            {
                // 阻止超链接跳转
                e.preventDefault();
                var startTime = Date.now();
                div = document.createElement('div');
                div.style.visibility = 'hidden';
                div.innerHTML = '<iframe id="schema" src="' + url + '" scrolling="no" width="1" height="1"></iframe>';
                document.body.appendChild(div);

                var delta = Date.now() - startTime;
                if(delta < 200){
                    setTimeout(function(){
                        window.location.href = downloadUrl;
                    }, 500);
                }
            }
        });
        if(isAppInstalled == 3) // 从微信中跳转到浏览器 已安装
        {
            var startTime = Date.now();
            div = document.createElement('div');
            div.style.visibility = 'hidden';
            div.innerHTML = '<iframe id="schema" src="' + url + '" scrolling="no" width="1" height="1"></iframe>';
            document.body.appendChild(div);
        }
        else if(isAppInstalled == 2) //从微信中跳转到浏览器, 未安装
        {
            window.location.href = downloadUrl;
        }
         $(".shadowDiv").click(function(e){
            $("#shadow").attr("height",0);
            $(this).removeClass("on");
         });
    }
    
function getPaomeApi(method, url, params, callback, errorback) {
  method = method == 'post' ? $.post : $.get;
  method(url, params, function(data){
    if(callback || errorback) {
      data = JSON.parse(data);
      if(data.error != undefined && data.error) {
        if(errorback) {
          errorback(data.error);
        } else {
          alert(data.error.text);
        }
      } else {
        callback(data.result);
      }
    }
  });
}
function rem(){
    var screenWidth = document.body.scrollWidth;
    function adapt(designWidth, rem2px){
      var d = window.document.createElement('div');
      d.style.width = '1rem';
      d.style.display = "none";
      var head = window.document.getElementsByTagName('head')[0];
      head.appendChild(d);
      var defaultFontSize = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width'));
      d.remove();
      // document.documentElement.style.fontSize = window.innerWidth / designWidth * rem2px / defaultFontSize * 100 + '%';
      var st = document.createElement('style');
      var portrait = "@media screen and (min-width: "+window.innerWidth+"px) {html{font-size:"+ ((window.innerWidth/(designWidth/rem2px)/defaultFontSize)*100) +"%;}}";
      var landscape = "@media screen and (min-width: "+window.innerHeight+"px) {html{font-size:"+ ((window.innerHeight/(designWidth/rem2px)/defaultFontSize)*100) +"%;}}"
      st.innerHTML = portrait + landscape;
      head.appendChild(st);
      return defaultFontSize
    };
    var defaultFontSize = adapt(screenWidth, 100);
}